import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Solution {
    public List<List<Integer>> threeSum(int[] nums){
        List<List<Integer>> ret = new ArrayList<>();

        //第1步，排序
        Arrays.sort(nums);

        //第2步，双指针算法解决
        int len = nums.length;
        for (int i = 0; i < len; ) {
            if(nums[i] > 0) break;
            int left = i+1, right = len-1, target = -nums[i];

            //利用查找两数之和的算法思想
            while(left < right){
                int sum = nums[left] + nums[right];
                if(sum < target) {
                    left++;
                } else if (sum > target) {
                    right--;
                } else if (sum == target) {
                    ret.add(new ArrayList<Integer>(Arrays.asList(nums[i],nums[left],nums[right])));
                    left++;right--;//缩小区间，继续寻找

                    //去重操作，同时要防止指针越界
                    while(left<right && nums[left]==nums[left-1]) left++;
                    while(left<right && nums[right]==nums[right+1]) right--;
                }
            }
            i++;
            while(i<len && nums[i] == nums[i-1]) i++;
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = in.nextInt();
            }
            Solution solution = new Solution();
            List<List<Integer>> result = solution.threeSum(arr);
            for (List<Integer> list : result) {
                System.out.print(list + " ");
            }
        }
    }
}
